package com.aha.secondchapter.second;

/**
 * 回文
 * Created by wangxin on 2015/10/31.
 */
public class Palindrome {
    public static void main(String[] args) {
        String str = "diffdfid";
        int len = str.length();
        int mid = len/2-1;
        char[] stack = new char[len];
        int top = 0;
        int next = 0;
        for (int i = 0; i <= mid; i++) {
            stack[++top] = str.charAt(i);
        }
        if(len%2==0){
            next = mid+1;
        }else{
            next = mid+2;
        }
        for (int j = next; j < len; j++) {
            char c = stack[top];
            char cc = str.charAt(j);
            if(c!=cc){
                break;
            }
            top--;
        }
        //top为0则说明栈内所有的字符都一一匹配了
        if(top==0) {
            System.out.println("true");
        }else {
            System.out.println("false");
        }
    }
}
